package model;

import helperclasses.DbUtil;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import javax.sql.DataSource;


public class UnitateMasura {
	ArrayList<String> uMasura = new ArrayList<String>();

	private Connection getConnection() throws SQLException {

		DataSource ds = DbUtil.getInstance().getDataSource();
		Connection conn = ds.getConnection();
		return conn;
	}

	public UnitateMasura() throws SQLException {
		SelectQuantities();
	}

	public ArrayList<String> getuMasura() {
		return uMasura;
	}

	public void setuMasura(ArrayList<String> uMasura) {
		this.uMasura = uMasura;
	}

	private void SelectQuantities() throws SQLException {
		Connection conn = getConnection();
		Statement st = conn.createStatement();
		try {

			ResultSet result = st.executeQuery("Select * from unitate_masura");
			while (result.next()) {
				uMasura.add(result.getString("tip"));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			st.close();
			conn.close();
		}

	}

}
